<style>
  .storeEdit .el-tabs__item.is-disabled{
    color: black;
    cursor: pointer;
  }
  .storeEdit .el-tabs--top .el-tabs__item.is-top.is-active {
    color:#1890ff;
  }
  .basicEdit .el-upload--picture-card{
    overflow: hidden;
  }
</style>
<style scoped>
  .tag{
    margin-right:50px;
  }
  video{
    width: 400px;
    height: 250px;
  }
</style>
<template>
  <div class="app-container storeEdit" style="background-color:#f3f5fa;">
    <div v-if="!$route.params.type" style="text-align:center;">
      <el-button v-hasPermi="['merchant:store:list']">
        <router-link :to="{path:'/merchant/store'}">返 回</router-link>
      </el-button>
    </div>
    <div v-if="$route.params.type" style="display:inline-block;background-color:#ffffff;border-radius:5px;width:400px;vertical-align:top;margin-right:30px;">
      <h5 style="padding-left:40px;">审核进度</h5>
      <div style="min-height:350px;">
        <el-timeline>
          <el-timeline-item
            v-for="(dict, index) in auditStatusMessage"
            :key="index"
            :timestamp="dict.code==0?'否':'是'">
            是否创建{{dict.name}}
          </el-timeline-item>
         </el-timeline>
      </div>
    </div>

    <!-- 添加或修改商户信息对话框 -->
    <div v-if="open" style="display:inline-block;background-color:#ffffff;width:calc(70%-30px);border-radius:5px;padding:0 30px 30px 30px;vertical-align:top;">
      <el-tabs v-model="tag" style="min-width:500px;" @tab-click="changeTag(tag)">
        <el-tab-pane disabled label="商户门店基本信息" name="5"></el-tab-pane>
        <el-tab-pane disabled label="商户门店联系人信息" name="6"></el-tab-pane>
        <el-tab-pane disabled label="商户资料信息" name="7"></el-tab-pane>
      </el-tabs>

      <el-form v-show="tag == 5" ref="formStore" :model="formStore" :rules="rulesStore" label-width="80px">
      <div>
        <el-form-item label="商户" prop="merchantNo">
          <el-select v-model="formStore.merchantNo" placeholder="请选择商户编号">
            <el-option
            v-for="dict in merchantOptions"
            :key="dict.no"
            :label="dict.cnName"
            :value="dict.no"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="门店中文名" prop="cnName">
          <el-input v-model="formStore.cnName" placeholder="请输入门店中文名" />
        </el-form-item>
        <el-form-item label="门店简称" prop="shortName">
          <el-input v-model="formStore.shortName" placeholder="请输入门店简称" />
        </el-form-item>
        <el-form-item label="门店英文名" prop="enName">
          <el-input v-model="formStore.enName" placeholder="请输入门店英文名" />
        </el-form-item>
        <el-form-item label="门店类型" prop="type">
          <el-select v-model="formStore.type" placeholder="请选择门店类型">
            <el-option
            v-for="dict in mbiStoreTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicense">
          <uploadImage v-model="formStore.businessLicense"/>
        </el-form-item>
        <el-form-item label="门店图片1" prop="showImg1">
          <uploadImage v-model="formStore.showImg1"/>
        </el-form-item>
        <el-form-item label="门店图片2" prop="showImg2">
          <uploadImage v-model="formStore.showImg2"/>
        </el-form-item>
        <el-form-item label="门店图片3" prop="showImg3">
          <uploadImage v-model="formStore.showImg3"/>
        </el-form-item>
        <el-form-item label="门店视频" ref="showVideo" prop="showVideo">
          <el-upload
            accept=".mp4"
            :action="uploadImgUrl"
            :on-success="handleUploadSuccess"
            :on-change="handleChange"
            :before-upload="handleBeforeUpload"
            :on-error="handleUploadError"
            :show-file-list="false"
            >
            <video v-if="formStore.showVideo"
              :src="formStore.showVideo"
              class="avatar video-avatar"
              controls="controls">
              您的浏览器不支持视频播放
            </video>
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="主门店" prop="mainStore">
          <el-radio-group v-model="formStore.mainStore">
            <el-radio
              v-for="dict in mbiStoreMainOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >
              {{dict.dictLabel}}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="门店开始日期" prop="openStartDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="formStore.openStartDate"
            type="date"
            value-format="yyyyMMdd"
            placeholder="选择门店开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="门店结束日期" prop="openEndDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="formStore.openEndDate"
            type="date"
            value-format="yyyyMMdd"
            placeholder="选择门店结束日期">
          </el-date-picker>
        </el-form-item>
      <div slot="footer" class="dialog-footer">
        <el-button v-hasPermi="['merchant:store:list']">
          <router-link :to="{path:'/merchant/store'}">列表页面</router-link>
        </el-button>
        <el-button type="primary" @click="submitFormStore">下一步</el-button>
      </div>
      </div>
      </el-form>

      <el-form v-show="tag == 6" ref="formStoreContact" :model="formStoreContact" :rules="rulesStoreContact" label-width="80px">
      <div>
        <el-form-item label="联系人名称" prop="contactName">
          <el-input v-model="formStoreContact.contactName" placeholder="请输入联系人名称" />
        </el-form-item>
        <el-form-item label="联系人手机" prop="contactMobile">
          <el-input v-model="formStoreContact.contactMobile" placeholder="请输入联系人手机" />
        </el-form-item>
        <el-form-item label="联系人座机" prop="contactTelephone">
          <el-input v-model="formStoreContact.contactTelephone" placeholder="请输入联系人座机" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="formStoreContact.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="邮编" prop="post">
          <el-input v-model="formStoreContact.post" placeholder="请输入邮编" />
        </el-form-item>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="lastStep">上一步</el-button>
        <el-button v-hasPermi="['merchant:store:list']">
          <router-link :to="{path:'/merchant/store'}">列表页面</router-link>
        </el-button>
        <el-button type="primary" @click="submitFormStoreContact">下一步</el-button>
      </div>
      </div>
      </el-form>

      <div v-show="tag == 7" style="background-color:#f3f5fa;">
      <el-form v-for="(d,index) in formData.merchantDataInfos" :key="index" :model="formData" label-width="80px" ref="formData" style="background-color:#ffffff;">
        <h3>{{formData.merchantDataInfos[index].dataName?formData.merchantDataInfos[index].dataName:'资料'+(index+1)}}
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-delete"
            @click="delDataContentList(index)"
            style="margin-left:50px;"
          >删 除</el-button>
        </h3>
        <el-form-item label="资料名称" :prop="'merchantDataInfos.'+index+'.dataName'" :rules="rulesData.dataName">
          <el-input
            v-model="formData.merchantDataInfos[index].dataName"
            placeholder="请输入资料名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="资料简介" :prop="'merchantDataInfos.'+index+'.synopsis'" :rules="rulesData.synopsis">
          <el-input
            v-model="formData.merchantDataInfos[index].synopsis"
            placeholder="请输入资料简介"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="资料类型编号" :prop="'merchantDataInfos.'+index+'.dataTypeCode'" :rules="rulesData.dataTypeCode">
          <el-select v-model="formData.merchantDataInfos[index].dataTypeCode" placeholder="请选择资料类型" clearable size="small">
            <el-option
            v-for="dict in mbiDataTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="资料图片1" :prop="'merchantDataInfos.'+index+'.dataImg1'" :rules="rulesData.dataImg1">
          <uploadImage v-model="formData.merchantDataInfos[index].dataImg1"/>
        </el-form-item>
        <el-form-item label="资料图片2" :prop="'merchantDataInfos.'+index+'.dataImg2'" :rules="rulesData.dataImg2">
          <uploadImage v-model="formData.merchantDataInfos[index].dataImg2"/>
        </el-form-item>
        <el-form-item label="资料文件" ref="dataFile" :prop="'merchantDataInfos.'+index+'.dataFile'" :rules="rulesData.dataFile">
          <el-upload
            :action="uploadImgUrl+'/'+index"
            :on-success="handleUploadSuccessData"
            :on-change="handleChange"
            :before-upload="handleBeforeUpload"
            :on-error="handleUploadError"
            :show-file-list="false"
            >
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
          <el-button v-if="formData.merchantDataInfos[index].dataFile" @click="downloadFileClick(formData.merchantDataInfos[index].dataFile)" size="small" type="primary">查看</el-button>
        </el-form-item>
        <el-form-item label="资料开始日期" :prop="'merchantDataInfos.'+index+'.dataStartDate'" :rules="rulesData.dataStartDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="formData.merchantDataInfos[index].dataStartDate"
            type="date"
            value-format="yyyyMMdd"
            placeholder="请选择资料开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="资料结束日期" :prop="'merchantDataInfos.'+index+'.dataEndDate'" :rules="rulesData.dataEndDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="formData.merchantDataInfos[index].dataEndDate"
            type="date"
            value-format="yyyyMMdd"
            placeholder="请选择资料结束日期">
          </el-date-picker>
        </el-form-item>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFormData(index)">保 存</el-button>
        </div>
        <el-divider content-position="right"></el-divider>
      </el-form>
      <div class="dialog-footer" ref="add">
        <el-button type="primary" @click="lastStep">上一步</el-button>
        <el-button v-hasPermi="['merchant:store:list']">
          <router-link :to="{path:'/merchant/store'}">列表页面</router-link>
        </el-button>
        <el-button type="primary" @click="addInputData">添 加</el-button>
        <el-button type="primary" @click="submitForm">提 交</el-button>
      </div>
      </div>

    </div>

    <!-- 审核对话框 -->
    <el-dialog :title="title" :visible.sync="auditOpen" width="500px" append-to-body>
      <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="80px">
        <el-form-item label="审核结果" prop="examineResult">
          <el-select v-model="auditForm.examineResult" placeholder="请选择审核结果">
            <el-option
            v-for="dict in exaResuOptionsAddAndUpdate"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核意见" prop="examineConclusion">
          <el-input v-model="auditForm.examineConclusion" placeholder="请输入审核意见" />
        </el-form-item>
        <el-form-item label="审核截止日期" prop="examineEndDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="auditForm.examineEndDate"
            type="date"
            value-format="yyyyMMdd"
            placeholder="选择审核截止日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="auditFormSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBasicAndOptions } from "@/api/merchant/basic";
import { getStore, addStore, updateStore, delStore, auditStore, getStoreByStoreNo, getMerchantStoreAuditMessage, submitStore } from "@/api/merchant/store";
import { listStoreContact, getStoreContact, delStoreContact, addStoreContact, updateStoreContact, exportStoreContact, getStoreContactByStoreNo } from "@/api/merchant/storeContact";
import { getData, getDataByNo, addData, updateData, addDataAndReturn, delData, getDataByStoreNo, auditData, logicRemoveByDataNo } from "@/api/merchant/data";
import UploadImage from '@/components/UploadImage';
import { getToken } from "@/utils/auth";

export default {
  name: "Basic",
  components: {
    UploadImage,
  },
  data() {
    return {
      // 上传的图片服务器地址
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/uploadToLongFileSystem",
      headers: {
        toekn: getToken(),
      },
      //显示的标签页
      tag: '1',
      // 遮罩层
      loading: true,
      // 门店编号
      storeNo: null,
      // 审核编号
      examineCode: null,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 商户类型集合
      mbiTypeOptions: [],
      //商户来源类型
      mbiSourceTypeOptions: [],
      //门店类型
      mbiStoreTypeOptions: [],
      //开通电子券
      mbiStoreOpenVoucherOptions: [],
      //主门店
      mbiStoreMainOptions: [],
      //布置二维码
      mbiStoreLayoutQrCodeOptions: [],
      //布置广告
      mbiStoreLayoutAdOptions: [],
      //布置物料
      mbiStoreLayoutMatterOptions: [],
      //资料类型
      mbiDataTypeOptions: [],
      //集团商户
      mbiBasicGroupMerchantOptions: [],
      //商户列表
      merchantOptions: [],
      // 审核结果字典
      exaResuOptions: [],
      // 审核结果字典
      exaResuOptionsAddAndUpdate: [],
      // 商户银行帐号类型字典
      mbiMerchantBankSettlementTypeOptions: [],
      // 总条数
      total: 0,
      //商户类型
      mbiType: [],
      //商户状态
      mbiStatus: [],
      //资料集合
      datas: [],
      // 审核进度信息
      auditStatusMessage: [],
      //标记是否查询过资料
      isQueryData: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      viewOpen: false,
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      auditOpen: false,
      // 是否提交基础信息
      isSubmitBasic: false,
      // 是否提交门店信息
      isSubmitStore: false,
      // 商户门店信息表单参数
      formStore: {},
      // 商户门店联系人信息表单参数
      formStoreContact: {},
      // 商户资料信息表单参数
      formData: {},
      // 审核表单参数
      auditForm: {},
      //商户门店信息表单校验
      rulesStore: {
        merchantNo: [
          { required: true, message: "商户不能为空", trigger: "blur" }
        ],
        cnName: [
          { required: true, message: "门店中文名不能为空", trigger: "blur" }
        ],
        shortName: [
          { required: true, message: "门店简称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "门店类型不能为空", trigger: "blur" }
        ],
        businessLicense: [
          { required: true, message: "营业执照不能为空", trigger: "blur" }
        ],
        showImg1: [
          { required: true, message: "门店图片1不能为空", trigger: "blur" }
        ],
        showImg2: [
          { required: true, message: "门店图片2不能为空", trigger: "blur" }
        ],
        showImg3: [
          { required: true, message: "门店图片3不能为空", trigger: "blur" }
        ],
        showVideo: [
          { required: true, message: "门店视频不能为空", trigger: "blur" }
        ],
        mainStore: [
          { required: true, message: "主门店不能为空", trigger: "blur" }
        ],
        openStartDate: [
          { required: true, message: "门店开始日期不能为空", trigger: "blur" }
        ],
        openEndDate: [
          { required: true, message: "门店结束日期不能为空", trigger: "blur" }
        ]
      },
      //商户门店联系人信息表单校验
      rulesStoreContact: {
        contactName: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" }
        ],
        contactMobile: [
          { required: true, message: "联系人手机不能为空", trigger: "blur" }
        ],
        contactTelephone: [
          { required: true, message: "联系人座机不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
        post: [
          { required: true, message: "邮编能为空", trigger: "blur" }
        ]
      },
      //商户资料信息表单校验
      rulesData: {
        dataName: [
          { required: true, message: "资料名称不能为空", trigger: "blur" }
        ],
        synopsis: [
          { required: true, message: "资料简介不能为空", trigger: "blur" }
        ],
        dataTypeCode: [
          { required: true, message: "资料类型不能为空", trigger: "blur" }
        ],
        dataImg1: [
          { required: true, message: "资料图片1不能为空", trigger: "blur" }
        ],
        dataImg2: [
          { required: true, message: "资料图片2不能为空", trigger: "blur" }
        ],
        dataFile: [
          { required: true, message: "资料文件不能为空", trigger: "blur" }
        ],
        dataStartDate: [
          { required: true, message: "资料开始时间不能为空", trigger: "blur" }
        ],
        dataEndDate: [
          { required: true, message: "资料结束时间不能为空", trigger: "blur" }
        ]
      },
      //商户审核信息表单校验
      auditRules: {
        examineResult: [
          { required: true, message: "审核结果不能为空", trigger: "blur" }
        ]
      }
    };
  },
  //每次进入页面时触发
  activated(){
  },
  //第一次进入页面时触发
  created() {
    this.reset();
    this.tag = "5";
    var params = this.$route.params;
    var type = params.type;
    if(type == 1){
      this.open = true;
      this.isSubmitBasic = false;
    }else if(type == 2 || type == 3 || type == 4){
      this.handleUpdate();
      if(type == 2 || type == 4){
        this.open = true;
        this.isSubmitBasic = true;
      }else if(type == 3){
        this.viewOpen = true;
      }
    }
    if(!this.no){
      this.auditStatusMessage.push({name:"商户门店基本信息",code: "0"})
    }
    this.getDicts("mct_merchant_type").then(response => {
      this.mbiTypeOptions = response.data;
    });
    this.getDicts("mct_merchant_source_type").then(response => {
      this.mbiSourceTypeOptions = response.data;
    });
    this.getDicts("mct_merchant_store_type").then(response => {
      this.mbiStoreTypeOptions = response.data;
    });
    this.getDicts("mct_merchant_store_open_voucher").then(response => {
      this.mbiStoreOpenVoucherOptions = response.data;
    });
    this.getDicts("mct_merchant_store_main").then(response => {
      this.mbiStoreMainOptions = response.data;
    });
    this.getDicts("mct_merchant_store_layout_qr_code").then(response => {
      this.mbiStoreLayoutQrCodeOptions = response.data;
    });
    this.getDicts("mct_merchant_store_layout_ad").then(response => {
      this.mbiStoreLayoutAdOptions = response.data;
    });
    this.getDicts("mct_merchant_store_layout_matter").then(response => {
      this.mbiStoreLayoutMatterOptions = response.data;
    });
    this.getDicts("mct_merchant_data_type").then(response => {
      this.mbiDataTypeOptions = response.data;
    });
    this.getDicts("mct_merchant_group_merchant").then(response => {
      this.mbiBasicGroupMerchantOptions = response.data;
    });
    this.getDicts("msg_message_template_examineResult_type").then(response => {
      this.exaResuOptions = response.data;
      this.exaResuOptions.forEach(element => {
        if(element.dictValue !=0){
          this.exaResuOptionsAddAndUpdate.push(element)
        }
      });
    });
    this.getDicts("mct_merchant_bank_settlement_type").then(response => {
      this.mbiMerchantBankSettlementTypeOptions = response.data;
    });
    listBasicAndOptions().then(response => {
      this.merchantOptions = response.rows;
    });
  },
  methods: {
    // 取消按钮
    cancel() {
      // 是否显示弹出层
      this.auditOpen = false;
    },
    // 表单重置
    reset() {
      // 是否显示弹出层
      this.viewOpen = false,
      // 是否显示弹出层
      this.open = false,
      // 是否显示弹出层
      this.auditOpen = false,
      this.formStore = {
        id: null,
        merchantNo: null,
        storeNo: null,
        cnName: null,
        shortName: null,
        enName: null,
        type: null,
        businessLicense: null,
        showImg1: null,
        showImg2: null,
        showImg3: null,
        showVideo: null,
        status: null,
        mainStore: "1",
        meanNo: null,
        openStartDate: null,
        openEndDate: null,
        examineCode: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      };
      this.formStoreContact = {
        id: null,
        merchantNo: null,
        storeNo: null,
        contactName: null,
        contactMobile: null,
        contactTelephone: null,
        address: null,
        post: null,
        examineCode: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      };
      this.formData = {
        merchantDataInfos: []
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleUpdate() {
      var params = this.$route.params;
      const storeNo = params.storeNo;
      this.loading = this.$loading({
        lock: true,
        text: "加载中",
        background: "rgba(0, 0, 0, 0.7)",
      });
      getStoreByStoreNo(storeNo).then(response =>{
        this.formStore = response.data;
        this.loading.close();
        var examineCode = this.formStore.examineCode;
        getStoreContactByStoreNo(this.formStore.storeNo).then(response => {
          if(response.data){
            this.formStoreContact = response.data
          }
        });
        getDataByStoreNo(this.formStore.storeNo).then(response => {
          this.formData = response.data;
          if(!this.formData.merchantDataInfos){
            this.formData.merchantDataInfos = [];
          }
          this.isQueryData = true;
        });
        var form = {};
        form.merchantNo = this.formStore.merchantNo;
        form.storeNo = this.formStore.storeNo;
        getMerchantStoreAuditMessage(form).then(response => {
          this.auditStatusMessage = response.data;
        });
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs.formStoreContact.validate(valid => {
        if (valid) {
          submitStore(this.formStore).then(response => {
            this.msgSuccess("保存成功");
          });
        }
      });
    },
    /** 门店信息提交按钮 */
    submitFormStore() {
      this.$confirm('是否确认,下一步会保存当前信息并且重新审核?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$refs.formStore.validate(valid => {
          if (valid) {
            if (this.formStore.id) {
              updateStore(this.formStore).then(response => {
                this.submitFormStorePublic();
              });
            } else {
              addStore(this.formStore).then(response => {
                this.msgSuccess("保存成功");
                this.formStore = response.data;
                this.storeNo = this.formStore.storeNo;
                this.examineCode = this.formStore.examineCode
                if(!this.isSubmitBasic){
                  this.isSubmitBasic = true;
                }
                this.submitFormStorePublic();
                var form = {};
                form.merchantNo = this.formStore.merchantNo;
                form.storeNo = this.formStore.storeNo;
                getMerchantStoreAuditMessage(form).then(response => {
                  this.auditStatusMessage = response.data;
                });
              });
            }
          }
        });
      }).catch(() => {});
    },
    /** 门店信息添加或修改成功后的操作 */
    submitFormStorePublic(){
      this.nextStep();
    },
    /** 门店联系人信息提交按钮 */
    submitFormStoreContact() {
      this.$refs.formStoreContact.validate(valid => {
        if (valid) {
          if (!this.formStoreContact.id) {
            this.formStoreContact.merchantNo = this.formStore.merchantNo;
            this.formStoreContact.examineCode = this.formStore.examineCode;
            this.formStoreContact.storeNo = this.formStore.storeNo;
            if(!this.formStoreContact.storeNo){
              this.msgSuccess("请先添加门店基础信息");
              return;
            }
          }
          updateStoreContact(this.formStoreContact).then(response => {
            this.nextStep();
            this.formStoreContact = response.data;
          });
        }
      });
    },
    /** 资料信息提交按钮 */
    submitFormData(index) {
      if(!this.formStore.id){
        this.msgSuccess("请先填写门店信息");
        return;
      }
      this.$refs.formData[index].validate(valid => {
        if (valid) {
          var obj = this.formData.merchantDataInfos[index];
          this.mbiDataTypeOptions.forEach(element => {
            if(obj.dataTypeCode == element.dictValue){
              obj.dataTypeDesc = element.remark;
            }
          });
          obj.examineCode = this.formStore.examineCode;
          if(obj.id){
            updateData(obj).then(response => {
              this.msgSuccess("保存成功");
            });
          }else{
            obj.merchantNo = this.formStore.merchantNo;
            obj.storeNo = this.formStore.storeNo;
            addDataAndReturn(obj).then(response => {
              this.formData.merchantDataInfos[index] = response.data;
              this.msgSuccess("保存成功");
            });
          }
        }
      });
    },
    /** 上一步按钮 */
    lastStep(){
      this.tag = parseInt(this.tag)-1+"";
    },
    /** 下一步按钮 */
    nextStep(){
      this.tag = parseInt(this.tag)+1+"";
    },
    /** 审核按钮 */
    handleUpdateAudit() {
      this.auditOpen = true;
    },
    /** 审核提交按钮 */
    auditFormSubmit(index) {
      this.$refs.auditForm.validate(valid => {
        if(valid){
          var form = this.auditForm;
          form.infoNo = this.formStore.storeNo;
          form.merchantNo = this.formStore.merchantNo;
          form.examineCode = this.formStore.examineCode;

          auditStore(form).then(response => {
            this.msgSuccess("审核成功");
            this.auditOpen = false;
          });
        }
      });
    },
    /** 删除资料按钮操作 */
    delDataContentList(index) {
      var arr = [];
      var mdie = this.formData.merchantDataInfos;
      var len = mdie.length;
      var dataNo;
      for(var i = 0; i < len; i++){
        if(i==index){
          dataNo = mdie[i].dataNo;
        }else{
          arr.push(mdie[i])
        }
      }
      if(!dataNo){
          this.formData.merchantDataInfos = arr
        return;
      }
      this.$confirm('是否确认删除商户信息编号为"' + dataNo + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return logicRemoveByDataNo(dataNo);
        }).then(() => {
          this.msgSuccess("删除成功");
          this.formData.merchantDataInfos = arr
        }).catch(() => {});
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
      var status = this.form.status;
      this.mbiStatus.forEach(element => {
        if(status == element.dictValue){
          this.form.status = element.dictLabel;
        }
      });
      var type = this.form.type.trim();
      this.mbiType.forEach(element => {
        if(type == element.dictValue){
          this.form.type = element.dictLabel;
        }
      });
      var sourceType = this.form.sourceType.trim();
      this.mbiSourceType.forEach(element => {
        if(sourceType == element.dictValue){
          this.form.sourceType = element.dictLabel;
        }
      });
    },
    /** 添加门店按钮操作 */
    addInputStore() {
      this.formStore.merchantStoreInfoExamines.push({});
    },
    /** 添加资料按钮操作 */
    addInputData() {
      this.formData.merchantDataInfos.push({});
    },
    //修改内容
    changeTag(index) {
    },
    //下载
    downloadFileClick(url) {
      window.open(url, '_target');
    },
    //文件上传成功
    handleUploadSuccess(res) {
      this.formStore.showVideo = res.url;
      this.loading.close();
      this.$refs.showVideo.clearValidate();
    },
    //文件上传成功
    handleUploadSuccessData(res) {
      var index = res.index;
      this.$set(this.formData.merchantDataInfos[index],"dataFile",res.url);
      this.loading.close();
      this.$refs.dataFile[index].clearValidate();
    },
    //文件上传之前
    handleBeforeUpload() {
      this.loading = this.$loading({
        lock: true,
        text: "上传中",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    //文件上传失败
    handleUploadError() {
      this.$message({
        type: "error",
        message: "上传失败",
      });
      this.loading.close();
    },
    //文件选择框被修改
    handleChange(file, fileList) {
      // 当多余一个的时候替换文件
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    }
  }
};
</script>
